#import "layer_game_touch.h"

#import "scene_game.h"
#import "layer_dialog.h"

@implementation LayerGameTouch

- (id)initLayerGameTouch
{
	if ((self = [super init]))
	{
		/*eable touch function
		*/
		self.isTouchEnabled = YES;
	}
	return self;
}

/*if layer return true : continue pass event
* if layer return false : stop pass event
*/

- (void)ccTouchesBegan:(NSSet *)Touch withEvent:(UIEvent *)Event
{
	CGPoint point;
	
	point = [self getTouchPoint:Touch];
	if (false == [g_SceneGame.layerDialog touchBegan:point])
	{
		return;
	}
	if (false == [g_SceneGame.layerObject touchBegan:point])
	{
		return;
	}
}

- (void)ccTouchesMoved:(NSSet *)Touch withEvent:(UIEvent *)Event
{
	CGPoint point;
	
	point = [self getTouchPoint:Touch];
	if (false == [g_SceneGame.layerDialog touchMoved:point])
	{
		return;
	}
	if (false == [g_SceneGame.layerObject touchMoved:point])
	{
		return;
	}
}

- (void)ccTouchesEnded:(NSSet *)Touch withEvent:(UIEvent *)Event
{
	CGPoint point;
	
	point = [self getTouchPoint:Touch];
	if (false == [g_SceneGame.layerDialog touchEnded:point])
	{
		return;
	}
	if (false == [g_SceneGame.layerObject touchEnded:point])
	{
		return;
	}
}

- (CGPoint)getTouchPoint:(NSSet *)Touch
{
	UITouch *touch;
	CGPoint point;
	
	touch = [Touch anyObject];
	point = [[CCDirector sharedDirector] convertToGL:[touch locationInView:[touch view]]];
	point = ConvertPositionToPositionInPixels(point);
	return point;
}

@end